#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e3+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn];
vector<string>v;
int main(void)
{
  string str="#";
  string ppp;cin>>ppp;
  str+=ppp;
  LL n;cin>>n;
  memset(dp,0x3f,sizeof(dp));
  for(LL i=0;i<n;i++){
    string s1="#";string s2;cin>>s2;
    s1+=s2;
    v.push_back(s1);
  }
  dp[0]=0;
  for(LL i=1;i<str.size();i++){
    for(LL j=0;j<n;j++){
        string k="";
        for(LL p=1;p<v[j].size();p++) {
                k+=v[j][p];
        }
        if(i<k.size()) continue;
        string f="";
        for(LL l=i-k.size()+1;l<=i;l++) {
                f+=str[l];
        }
        if(f==k){
            dp[i]=min(dp[i],dp[i-k.size()]+1);
        }
    }
  }
  cout<<dp[str.size()-1]<<'\n';
return 0;
}
